package strategyPattern

import "fmt"

type strategy interface {
	Algorithm()
}

type strategyA struct{}
type strategyB struct{}
type strategyC struct{}

func (strategy *strategyA) Algorithm() {
	fmt.Println("执行策略A")
}
func (strategy strategyB) Algorithm() {
	fmt.Println("执行策略B")
}
func (strategy strategyC) Algorithm() {
	fmt.Println("执行策略C")
}

type context struct {
	strategy strategy
}

func NewContext(strategy strategy) *context {
	return &context{strategy: strategy}
}

func (context *context) algorithm() {
	context.strategy.Algorithm()
}

func Doit() {
	ctx := NewContext(&strategyA{})
	ctx.algorithm()

	ctx = NewContext(strategyB{})
	ctx.algorithm()

	ctx = NewContext(strategyC{})
	ctx.algorithm()
}
